<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-10-04
 * Time: 11:57
 */
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\UserData as cxModel;

class UserData extends Apibase{
    /**
     * 本方法仅接收post值
     * @return \think\response\Json
     */
    public function get_uid(){
        if(request()->isPost()){
            $cxmodel = new cxModel();
            $data = input('post.');
            $data = datatrim($data);
            if(!empty($data['m'])){
                $map['group_id'] = array('in',$data['m']);
            }
            $map['username|uniname|uemail|uname|uphone'] = array('like',"%".$data['k']."%");
            $aids = $cxmodel->where($map)->where('status','1')->order('uid desc')->select();
            $getaid = array();
            if(!empty($aids) && isset($aids)){
                foreach ($aids as $v){
                    $v = $v->toArray();
                    //  是否需要查询老师课程安排
                    if(!empty($data['has']) && !empty($data['hat'])){
                        $maketime = $data['has'].' '.$data['hat'];
                        $maketime = strtotime($maketime);
                        $makeres = false;
                        $makes = model('OrderMake')->where('vipuid',$v['uid'])->where('vipstatus','1')->where('maketime','>',$maketime)->order('maketime desc')->find();
                        if(!empty($makes)){
                            $makes = $makes->toArray();
                            $minmaketime = $makes['maketime'] - 7200;
                            $maxmaketime = $makes['maketime'] + 7200;
                            if($maketime > $minmaketime && $maketime < $maxmaketime){
                                $makeres = true;
                            }
                        }
                        $makex = model('OrderMake')->where('vipuid',$v['uid'])->where('vipstatus','1')->where('maketime','<',$maketime)->order('maketime asc')->find();
                        if(!empty($makex)){
                            $makex = $makex->toArray();
                            $minmakextime = $makex['maketime'] - 7200;
                            $maxmakextime = $makex['maketime'] + 7200;
                            if($maketime > $minmakextime && $maketime < $maxmakextime){
                                $makeres = true;
                            }
                        }
                        $v['makeres'] = $makeres;
                    }
                    $getaid[] = $v;
                }
            }
            return json($getaid);
        }
    }
}